
<%--
  Created by IntelliJ IDEA.
  User: 莫
  Date: 2017/12/20
  Time: 21:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<nav class="navbar navbar-default">
    <div class="navbar-header">
        <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-exl-collapse"><i class="fa fa-bars"></i></button>
        <a class="navbar-brand" href="#">后台管理</a>
    </div>
    <div class="collapse navbar-collapse navbar-exl-collapse">
        <ul class="nav navbar-nav">
            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
            <li><a href="#">Link</a></li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                <ul class="dropdown-menu">
                    <li><a href="#">Action</a></li>
                    <li><a href="#">Another action</a></li>
                </ul>
            </li>
        </ul>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-2">
            <a href="NewsManage_Admin.jsp" class="list-group-item active">新闻管理</a>
            <a href="User_Admin.jsp" class="list-group-item">用户管理</a>
        </div>
        <div class="col-sm-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    搜索
                </div>
                <div class="panel-body">
                    <form role="form" class="form-inline" action="">
                        <div class="form-group">
                            <label for="name">名称</label>
                            <input type="text" class="form-control" id="name" placeholder="请输入名称">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-default">开始搜索</button>
                        </div>
                    </form>
                </div>
            </div>
            <!--
                列表展示
            -->
            <div class="table-responsive">
                <table class="table table-striped " id="table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>标题</th>
                        <th>作者</th>
                        <th>时间</th>
                        <th>审核情况</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
            <ul class="pagination" style="float: right;">
                <li><a href="#">&laquo;</a>
                </li>
                <li class="active"><a href="#">1</a>
                </li>
                <li class="disabled"><a href="#">2</a>
                </li>
                <li><a href="#">3</a>
                </li>
                <li><a href="#">4</a>
                </li>
                <li><a href="#">5</a>
                </li>
                <li><a href="#">&raquo;</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<button></button>
<script>
    var xmlhttp;
    window.onload = function () {
        xmlhttp=new XMLHttpRequest();
        xmlhttp.open("POST","TableHtml",false);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("FN=1");

        var news = JSON.parse(xmlhttp.responseText);
        var NewsList = news.NewsList;

        var table = document.getElementById("table");
        for (var i = 0;i<NewsList.length;i++)
        {
            var row = table.insertRow(table.rows.length);
            var ID = row.insertCell(0);
            ID.innerHTML = NewsList[i].Id;
            var Head = row.insertCell(1);
            Head.innerHTML = "<a href=\"NewsContents.jsp?name="+NewsList[i].Headline+"\">"+NewsList[i].Headline+"</a>";
            var Name = row.insertCell(2);
            Name.innerHTML = NewsList[i].Name;
            var Time = row.insertCell(3);
            Time.innerHTML = NewsList[i].UpTime;
            var Check = row.insertCell(4);
            if(NewsList[i].Check == 1) {
                Check.innerHTML = "已通过";
            }
            else if(NewsList[i].Check == 2){
                Check.innerHTML = "未通过";
            }
            else  Check.innerHTML = "审核中";
            var OpenNews = row.insertCell(5);
            OpenNews.innerHTML = "<input type='button' value='通过' title='"+NewsList[i].Id+"'><button title='"+NewsList[i].Id+"'>删除</button>";


        }
//审核
        var inpts = document.getElementsByTagName("input");
        console.log(inpts);
        var len = inpts.length;
        console.log(len)
        for(var i = 1;i<len;i++)
        {
            var inpt = inpts[i];
            inpt.onclick = function () {
                var id = this.title;
                xmlhttp=new XMLHttpRequest();
                xmlhttp.open("POST","CheckHtml",false);
                xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                xmlhttp.send("id="+id+"&check=1");

                window.location.reload();
            }
        }
//删除
        var buts = document.getElementsByTagName("button");
        console.log(buts);
        var len_but = buts.length;
        for(var i = 2;i<len_but;i++)
        {
            var but = buts[i];
            but.onclick = function () {
                var id = this.title;
                xmlhttp=new XMLHttpRequest();
                xmlhttp.open("POST","DeleteHtml",false);
                xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                xmlhttp.send("id="+id);

                window.location.reload();
            }
        }


        // var news=[{"uid":"2688","uname":"*江苏省南菁高级中学 022","sum":274.23},{"uid":"2689","uname":"*江阴国际会展中心管理有限公司 024","sum":0},{"uid":"2686","uname":"江苏申利实业股份有限公司 001","sum":7917.94},{"uid":"2715","uname":"江阴市吉达针纺有限公司 115","sum":41.39},{"uid":"2688","uname":"*江苏省南菁高级中学 022","sum":274.23}]
        //
        // for (var i = 0;i<news.length;i++)
        // {
        //     var row = table.insertRow(table.rows.length);
        //     var ID = row.insertCell(0);
        //     ID.innerHTML = news[i].uid;
        //     var Head = row.insertCell(1);
        //     Head.innerHTML = news[i].uname;
        //     var Name = row.insertCell(2);
        //     Name.innerHTML = news[i].sum;
        // }
    }
</script>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>




